package com.qf.controller;

import java.util.Arrays;
import java.util.List;


import com.qf.entity.Goods;
import com.qf.entity.GoodsEntity;
import com.qf.entity.Stock;
import com.qf.entity.StockParam;
import com.qf.service.GoodsService;
import com.qf.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 
 *
 * @author liuzishuo
 * @email sunlightcs@gmail.com
 * @date 2021-07-08 11:21:45
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @Autowired
    private StockService stockService;
    @RequestMapping("/list")
    public List<GoodsEntity> list(){
        List<GoodsEntity> goodsEntityList = goodsService.list();
        return goodsEntityList;
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public GoodsEntity info(@PathVariable("id") Integer id){
		GoodsEntity goods = goodsService.getById(id);

        return goods;
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public GoodsEntity save(@RequestBody GoodsEntity goods){
        boolean save = goodsService.save(goods);

        return goods;
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public boolean update(@RequestBody GoodsEntity goods){
        boolean update = goodsService.updateById(goods);
        return update;
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public boolean delete(@RequestBody Integer[] ids){
        boolean remove = goodsService.removeByIds(Arrays.asList(ids));
        return remove;
    }

    @RequestMapping("/saveGoodsAndStock")
    public  Goods saveGoodsAndStock(@RequestBody Goods goods){
          goodsService.saveGoodsAndStock(goods);
         return goods;
    }
    @RequestMapping("/lock")
    @ResponseBody
    boolean lockStock(@RequestBody List<StockParam> stockParamList){
      return stockService.lockStock(stockParamList);
    }
}
